package Com.itheima;

import java.util.*;

public class CollectionsDemo {
    public static void main(String[] args) {
        test1();
    }
    public static void test1(){
        List<Integer> list = new ArrayList<>();
        Collections.addAll(list, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
        //按照正序给集合排序
        Collections.sort(list);
        list.forEach(System.out::println);

        System.out.println("------------------------------------");
        //按照倒叙排
        Collections.sort(list,((o1, o2) -> {
            return o2 - o1;
        }));
        list.forEach(System.out::println);
        //让学生实现Student类实现Comparable接口，这样也能排序
        System.out.println("------------------------------------");
        List<Student> list1 = new ArrayList<>();
        list1.add(new Student("张三", 18));
        list1.add(new Student("王五", 20));
        list1.add(new Student("李四", 19));

        Collections.sort(list1);
        list1.forEach(System.out::println);




    }


}
